import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import { resolve } from 'path'
/* import fs from 'fs' */


export default defineConfig({
  plugins: [vue()],
  resolve: {
    alias: {
      '@': resolve(__dirname, 'src')
    }
  },
  server: {
    port: 5181,
    host: false,
    // 配置代理转发API请求到后端
    proxy: {
      '/api': {
        target: 'http://localhost:5000',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api/, '/api')
      },
      // 静态上传资源从后端提供，前端开发服务器仅做转发
      '/uploads': {
        target: 'http://localhost:5000',
        changeOrigin: true
      }
    },
    // 启用 HTTPS
    /* https: {
      key: fs.readFileSync('./localhost-key.pem'),
      cert: fs.readFileSync('./localhost.pem')
    } */
  }
})